package Leetcode.LeetcodeDemo1;

public class LeetCode240 {
    public static void main(String[] args) {
        int[][] arr={{1,4,7,11,15},{2,5,8,12,19},{3,6,9,16,22},{10,13,14,17,24},{18,21,23,26,30}};
        System.out.println(searchMatrix(arr,19));
    }
    public static boolean searchMatrix(int[][] matrix, int target) {
        int i=0,j=0;
        boolean output=false;
        while(true){
            if(j==matrix[i].length-1){
                i++;
                j=0;
            }
            if(matrix[i][j+1]>target){
                i++;
                j=0;
            }
            if(matrix[i][j+1]<=target){
                j++;
            }
            if(matrix[i][j]==target){
                output=true;
                break;
            }
        }
        return output;
    }
}
